﻿using UnityEngine;
using System.Collections;


public class OC_ItemPanelController : OC_PanelController
{
    CharacterInfoScene charscene;

    public OC_ScrollUIForItem m_ScrollItemList;

    public Oc_ItemNoticeBox m_LeftBox;
    public Oc_ItemNoticeBox m_RightBox;

    public Animation m_LeftBottomAni;
    public Animation m_CharMoveAni;

    const float ListOutDelay = 3.0f;
   

    public void UpdateUI(bool isNeedItemReset)
    {
        charscene = CharacterInfoScene.Instance as CharacterInfoScene;
        m_ScrollItemList.UpdateItemsList(charscene.m_SelectMember, isNeedItemReset);    // 아이템 리스트 스크롤뷰 컨트롤러 이용

        m_LeftBox.SetItem(charscene.m_SelectMember.leftItem, true);
        m_RightBox.SetItem(charscene.m_SelectMember.rightItem, false);
    }


    public override void ButtonTouch(Collider collider)  // 버튼 터치 (터치 시작 끝 같은 오브젝트일때 터치 끝 시점에 호출)
    {
       
        {
            switch (collider.gameObject.name)
            {
                case "Button_LeftItemOpen":
                    {
                        m_LeftBox.SetOn(true);
                        m_RightBox.SetOn(false);
                        //(지스타임시)퀘스트 인디케이터 가리기
                        QuestManager.instance.HideTouchIndicator();
                    }
                    break;
                case "Button_RightItemOpen":
                    {
                        m_RightBox.SetOn(true);
                        m_LeftBox.SetOn(false);
                        //(지스타임시)퀘스트 인디케이터 가리기
                        QuestManager.instance.HideTouchIndicator();
                    }
                    break;
                case "Button_LeftItemListClose":
                    {
                        m_LeftBox.SetOn(false);                       
                    }
                    break;
                case "Button_RightItemListClose":
                    {                        
                        m_RightBox.SetOn(false);
                    }
                    break;
                case "Button_GoChange":
                    {
                        MemberListIn();
                    }
                    break;
            }
        }
    } 

    void MemberListIn()
    {
        charscene = CharacterInfoScene.Instance as CharacterInfoScene;
        charscene.m_MemberListRoot.transform.parent = transform;

        // 드래그 이벤트 취소
        foreach (Oc_MemberListItem t in charscene.m_LeftListItems)
        {
            t.m_EventRecieaver = gameObject;
            t.m_OnDrag = "RefreshMemberListOut";
            t.m_OnPress = "RefreshMemberListOut";
        }

        charscene.MemberListAni(true);

        m_LeftBottomAni.Play("CharacterInfo_Item_LeftBottom_Alpha_out");
        m_CharMoveAni.Play("char_Member_change IN");

        RefreshMemberListOut();
    }


    public void RefreshMemberListOut()
    {
        CharacterInfoScene root = CharacterInfoScene.Instance as CharacterInfoScene;
       
        StopCoroutine("MemberListOut");
        StartCoroutine("MemberListOut", ListOutDelay);      
    }
    
    IEnumerator MemberListOut(float time)
    {
        yield return new WaitForSeconds(time);

        CharacterInfoScene root = CharacterInfoScene.Instance as CharacterInfoScene;        
        root.MemberListAni(false);
        m_LeftBottomAni.Play("CharacterInfo_Item_LeftBottom_Alpha_in");
        m_CharMoveAni.Play("char_Member_change OUT");        
    }
}

